package cn.adviceclient.features.module;

import cn.adviceclient.event.impl.Render2DEvent;
import cn.adviceclient.event.impl.Render3DEvent;
import cn.adviceclient.features.value.AbstractSetting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.network.NetHandlerPlayClient;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class Module {
    protected String name;
    protected String description;
    protected Category category;
    protected boolean enabled = false;
    protected int key = -1;

    public final CopyOnWriteArrayList<AbstractSetting<?>> settings = new CopyOnWriteArrayList<>();

    public final Minecraft mc = Minecraft.getMinecraft();

    public Module(String name, String description, Category category) {
        this.name = name;
        this.description = description;
        this.category = category;
    }

    public void onEnable() {}
    public void onDisable() {}

    public void onTick() {}
    public void onRender2D(Render2DEvent event) {}
    public void onRender3D(Render3DEvent event) {}


    public void enable() {
        this.enabled = true;
        onEnable();
    }

    public void disable() {
        this.enabled = false;
        onDisable();
    }

    public void toggle() {
        if (enabled) {
            disable();
        } else {
            enable();
        }
    }

    public void bindKey(int key) {
        this.key = key;
    }

    public boolean isEnabled() {
        return enabled;
    }
    
    public boolean getEnabled() {
        return enabled;
    }

    public String getName() {
        return name;
    }

    public int getKey() {
        return key;
    }
    
    public int getKeyBind() {
        return key;
    }

    public Category getCategory() {
        return category;
    }
    
    /**
     * Gets all settings for this module
     */
    public List<AbstractSetting<?>> getSettings() {
        return settings;
    }
    
    /**
     * Adds a setting to this module
     */
    public <T extends AbstractSetting<?>> T addSetting(T setting) {
        settings.add(setting);
        return setting;
    }
}